home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / C++ AppleLink Messages / CPlus.Dev$ 7⁄6⁄90 / 0153-const volatile missi-Jul90 next >
Encoding:
Text File  |  1990-07-06  |  1.4 KB  |  49 lines  |  [TEXT/GEOL]

  1. Item    1936340                         2-July-90        00:43PDT
  2.  
  3. From:   D0532                           Aidea Systems, Don Park,PRT
  4.  
  5. To:     CPLUS.DEV$                      C++ Interest List--Developers
  6.         CPLUS.APPLE$                    C++ Interest List--Apple Employees
  7.  
  8. Sub:    const volatile missing!!!
  9.  
  10. Here is a difference between ANSI C and C++ 2.0 I didn't know about:
  11.  
  12. ANSI C allows 'const' and 'volatile' to be used together to declare variables
  13. that only external processes can change.
  14.  
  15. C++ 2.0 apparently does not allow this although there is no mention of this
  16. incompatiability in the latest manual (Annotated C++ Reference Manual).
  17.  
  18. Example Code:
  19.  
  20.     const volatile int xCopyDone = 0;   /* x is for external data */
  21.     volatile const int xCopyError = 0;  /* order has no effect */
  22.  
  23.         int
  24.     WaitForCopy ( void )
  25.     {
  26.         while (!xCopyDone)
  27.             Meditate();
  28.         return xCopyError;
  29.     }
  30.  
  31. ANSI C will allocate xCopyDone and xCopyError as external data while C++ uses
  32. them as constants.  Thus the code is translated into following:
  33.  
  34.         int
  35.     WaitForCopy__Fv ( void )            /* mangley doodley */
  36.     {
  37.         while (1)
  38.             Meditate__Fv();
  39.         return (int)0;
  40.     }
  41.  
  42. Using 'extern' with initializer will allocate them but code is for
  43. WaitForCopy() is still the same over friendly puke.
  44.  
  45. So, be aware and prosper if it can be implemented!
  46.  
  47. Don Park
  48.  
  49.